package com.wuyou.sso.handler.login;

import com.wuyou.sso.domain.vo.UserVO;
import com.wuyou.sso.common.enums.LoginTypeEnum;
import com.wuyou.sso.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * UsernamePasswordHandler
 *
 * @Date 2025/4/24 17:18
 * @Author 无忧
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class UsernamePasswordHandler implements LoginHandler {


    private final UserService userService;
    private final PasswordEncoder passwordEncoder;

    /**
     * 用户名密码登录
     * @param loginStr
     * @return
     */
    @Override
    public UserVO handle(String loginStr) {
        UserVO userVO = userService.getUserByUserName(loginStr);
        return userVO;
    }

    @Override
    public Boolean support(LoginTypeEnum type) {
        return LoginTypeEnum.PWD.equals(type);
    }
}
